function mySetInterval(fn, t) {
  let timer = null;
  const interval = () => {
    timer && fn();
    timer = setTimeout(interval, t);
  }
  interval();
  return {
    clearMyInterval: () => {
      clearTimeout(timer);
    }
  }
}

const { clearMyInterval } = mySetInterval(() => {
  console.log(111);
}, 1000);

setTimeout(clearMyInterval, 5000);